// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    let data = event.data
    data._openid = wxContext.OPENID
    data.time = new Date()
    let goods = await db.collection('usedGoods_list').add({
        data: data
    })


    data._id = goods._id
    await db.collection('gods').where({
        _openid: wxContext.OPENID,
    }).update({
        data: {
            'publish.usedGoods': _.push(data),
            btList: _.push({
                name: "发布二手物品信息",
                time: new Date(),
                num: 5
            })
        }
    })

    return data
}